<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/6
 * Time: 12:36
 */

namespace Api\Controller;
use Admin\Model\HouseModel;
use Admin\Model\IndustryModel;
use Admin\Model\OrganizationModel;

class OrganizationController extends ApiController
{
    private $org;
    private $houseModel;
    private $industryModel;

    function __construct() {
        parent::__construct();
        $this->org =  new OrganizationModel();
        $this->houseModel = new HouseModel();
        $this->industryModel = new IndustryModel();
    }
    //街道列表(组织)
    public function lists(){
        //$flag = I('flag');
        $data = $this->org->getOrgAllList(array('status'=>1));//街道列表数据
        return $this->callBack("街道列表",$this->SUCCESS_CODE,$data);

    }

    public function getList() {
        $data = $this->org->where(array('status'=>1))->field('id,name')->select();
        $this->response('成功！',$this->SUCCESS_CODE,$data);
    }

    public function getHouse() {
        $user_id = I('user_id');
        if (!$user_id) {
            return $this->response('无效的请求参数',1);
        }
        $userHouseId = array();
        $userHouses = M('user_sweep')->where(array('user_id' => $user_id))->field('house_id')->select();
        foreach ($userHouses as $row) {
            $userHouseId[] = $row['house_id'];
        }
        $userHouseId = $userHouseId ? $userHouseId : array(0);
        $orgId = I('orgId');
        $where = array('status' => 1);
        if ($orgId) {
            $where['org_id'] = $orgId;
        }
        $where['id'] = array('in',$userHouseId);
        $houses = $this->houseModel->where($where)->field('id,name')->select();
        $this->response('成功！',$this->SUCCESS_CODE,$houses);
    }

    public function getIndustry() {
        $data = $this->industryModel->where(array('status'=>1))->field('id,name')->select();
        $this->response('成功！',$this->SUCCESS_CODE,$data);
    }

    public function getCompanyType() {
        $data = array(
            array('id' => '1', 'name' => '公司'),
            array('id' => '2', 'name' => '分公司'),
            array('id' => '3', 'name' => '办事处'),
            array('id' => '4', 'name' => '个体'),
            array('id' => '5', 'name' => '无照'),
            array('id' => '6', 'name' => '在办'),
            array('id' => '7', 'name' => '其他')
        );
        $this->response('成功！',$this->SUCCESS_CODE,$data);
    }
}